package com.onpositive.datacollection.editor;

import com.onpositive.datamap.IDataPropertyValue;
import com.onpositive.datamap.values.impl.PlainTextTokenAcceptor;
import com.onpositive.semantic.model.api.labels.ITextLabelProvider;
import com.onpositive.semantic.model.api.meta.IHasMeta;
import com.onpositive.semantic.model.ui.richtext.IRichLabelProvider;
import com.onpositive.semantic.model.ui.richtext.StyledString;
import com.onpositive.semantic.model.ui.richtext.StyledString.Style;

public class DataPropertyValueLabelProvider implements ITextLabelProvider,IRichLabelProvider {

	/**
	 * s
	 */
	private static final long serialVersionUID = 1L;

	public DataPropertyValueLabelProvider() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public String getText(IHasMeta meta, Object parent, Object object) {
		PlainTextTokenAcceptor t=new PlainTextTokenAcceptor();
		IDataPropertyValue p=(IDataPropertyValue) object;
		p.render(t);
		return t.toString();
	}

	@Override
	public String getDescription(Object object) {
		return null;
	}

	@Override
	public StyledString getRichTextLabel(Object object) {
		final StyledString s=new StyledString();
		PlainTextTokenAcceptor t=new PlainTextTokenAcceptor(){
			@Override
			public void acceptInternalIdentifier(String text, String number,
					String propertyId) {
				s.append(text,new Style("HYPERLINK_COLOR",""));
				super.acceptInternalIdentifier(text, number, propertyId);
			}
			@Override
			public void acceptPlainText(String text, int style) {
				s.append(text);
			}
			@Override
			public void acceptComparableValue(String text, String propertyId,
					Object value) {
				acceptPlainText(text, BOLD);
			}
			@Override
			public void acceptValueSeparator() {
				s.append(',');
			}
			@Override
			public void acceptExternalIdentifier(String text, String url,
					String propertyid) {
				acceptInternalIdentifier(text, url, propertyid);
			}
		};
		
		IDataPropertyValue p=(IDataPropertyValue) object;
		p.render(t);
		return s;		
	}

}
